package com.cqan.log.entity;

import java.util.Date;
import java.util.Map;

import javax.persistence.Column;
import javax.persistence.MappedSuperclass;
import javax.ws.rs.core.HttpHeaders;

import com.cqan.common.Constant;
import com.cqan.entity.pk.LongEntity;

/**
 * 封装基本日志信息
 * @author slaton
 *
 */
@MappedSuperclass
@SuppressWarnings("serial")
public abstract class BasicLog extends LongEntity {

	//appid
	private String ab;

	//会话ID
	private String asid;

	//渠道id
	private String cid;

	//记录时间
	private Date ctime;

	//设备ID号
	private String did;

	//平台
	private String flat;

	//请求IP
	private String ip;

	//语言版本
	private String language;
	
	//系统平台
	private String sm;
	
	//系统版本号
	private String sv;
	
	//User agent 设备型号
	private String ua;
	
	//用户id
	private String uid;
	
	//当前客户端版本号
	private String version;
	
	@Column(name="AB")
	public String getAb() {
		return ab;
	}

	@Column(name="ASID")
	public String getAsid() {
		return asid;
	}
	
	@Column(name="CID")
	public String getCid() {
		return cid;
	}

	@Column(name="CTIME")
	public Date getCtime() {
		return ctime;
	}

	@Column(name="DID")
	public String getDid() {
		return did;
	}

	@Column(name="FLAT")
	public String getFlat() {
		return flat;
	}

	@Column(name="IP")
	public String getIp() {
		return ip;
	}

	@Column(name="LANGUAGE")
	public String getLanguage() {
		return language;
	}

	@Column(name="SM")
	public String getSm() {
		return sm;
	}

	@Column(name="SV")
	public String getSv() {
		return sv;
	}

	@Column(name="UA")
	public String getUa() {
		return ua;
	}

	@Column(name="UID")
	public String getUid() {
		return uid;
	}

	@Column(name="VERSION")
	public String getVersion() {
		return version;
	}

	public void setAb(String ab) {
		this.ab = ab;
	}

	public void setAsid(String asid) {
		this.asid = asid;
	}

	public void setCid(String cid) {
		this.cid = cid;
	}

	public void setCtime(Date ctime) {
		this.ctime = ctime;
	}

	public void setDid(String did) {
		this.did = did;
	}

	public void setFlat(String flat) {
		this.flat = flat;
	}

	public void setIp(String ip) {
		this.ip = ip;
	}

	public void setLanguage(String language) {
		this.language = language;
	}

	public void setSm(String sm) {
		this.sm = sm;
	}

	public void setSv(String sv) {
		this.sv = sv;
	}

	public void setUa(String ua) {
		this.ua = ua;
	}

	public void setUid(String uid) {
		this.uid = uid;
	}

	public void setVersion(String version) {
		this.version = version;
	}
	
	public BasicLog(){}
	
	public BasicLog(HttpHeaders headers){
		Map<String, String> header = Constant.getHeader(headers);
		this.setAb(header.get("ab"));
		this.setAsid(header.get("asid"));
		this.setCid(header.get("cid"));
		this.setCtime(new Date());
		this.setDid(header.get("did"));
		this.setFlat(header.get("flat"));
		this.setLanguage(header.get("language"));
		this.setSm(header.get("sm"));
		this.setSv(header.get("sv"));
		this.setUa(header.get("ua"));
		this.setUid(header.get("uid"));
		this.setVersion(header.get("version"));
	}

}
